package com.tju.welding.controller;

import javax.servlet.http.HttpSession;

import com.tju.welding.service.UserService;
import com.tju.welding.utils.ApiResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/api/user/register")
    public ApiResponse register(@RequestParam("realName") String realName, @RequestParam("password") String password,
            @RequestParam("userType") int userType, @RequestParam("phoneNumber") String phoneNumber) {

        return userService.register(realName, password, userType, phoneNumber);

    }

    @PostMapping("/api/user/login")
    public ApiResponse login(@RequestParam("phoneNumber") String phoneNumber, @RequestParam("password") String password, HttpSession session) {

        return userService.login(phoneNumber, password, session);

    }

    @PostMapping("/api/user/logout")
    public ApiResponse logout(HttpSession session) {

        return userService.logout(session);

    }

}
